import { ref, computed } from 'vue'
import { defineStore } from 'pinia'
import router from '@/router/index';


export interface Course {
  name: string;
  author: string;
  students: number;
  context: string;
  grade:string;
}

export const courseStore = defineStore('courses', {
  state: () => ({
    course: {} as Course,
   name:'智能机械',
    author:'',
    grade:'',
   context:'',
   selectedOption :'免费',
   stutes:'基础',
   students:100,
   viewNumber:1000,
   adoreNumber:300,
   collectNumber:200,
   downloadNum:100,
   shareNumber:100,
   adore:false,
   collect:false,
   download:false,
   share:false,
   ing:true,
  }),

  actions: {
   
      addCourse(name: string, author: string, context: string, grade: string, students: number) {
        const defaultCourse: Course = {
          name: name || '',
          author: author || '',
          students: students || 100,
          context: context || '',
          grade: grade || '',
        };
  
        this.course = defaultCourse;
        console.log(this.course);
        alert('提交成功')
      },
      removeCourse() {
        this.course = {} as Course;
      },
  
      updateCourseName(name: string) {
        this.course.name = name;
        console.log(name)
      },
  
      updateCourseAuthor(author: string) {
        this.course.author = author;
        console.log(author)
      },

      updateCourseContext(context: string) {
        this.course.context = context;
        console.log(context)
      },
  
      updateCourseGrade(grade: string) {
        this.course.grade = grade;
      },
      incrementStudents() {
        this.course.students += 1;
        this.students++;
      },
      deleteStudents() {
        this.course.students=this.course.students-1;
        this.students--;
      },
  },
});